﻿using System;
using StudentInfo.Security.Enums;

namespace StudentInfo
{
    public partial class RolePermission
    {
        private CrudType crudType { get; set; }

        public CrudType CrudType
        {
            get
            {
                if (crudType == 0)
                    crudType = setPermissionFlag(CrudType.CanCreate, CanCreate) |
                               setPermissionFlag(CrudType.CanRead, CanRead) |
                               setPermissionFlag(CrudType.CanUpdate, CanUpdate) |
                               setPermissionFlag(CrudType.CanDelete, CanDelete);
                return crudType;
            }
        }

        private static CrudType setPermissionFlag(CrudType crudType, bool permission)
        {
            return (CrudType)((int)crudType * Convert.ToInt32(permission));
        }
    }
}